#include "../host/host.h"

/* Button bit masks */
#define SCE_CTRL_SELECT     0x0001
#define SCE_CTRL_START      0x0008

#define SCE_CTRL_UP         0x0010
#define SCE_CTRL_RIGHT      0x0020
#define SCE_CTRL_DOWN       0x0040
#define SCE_CTRL_LEFT       0x0080

#define SCE_CTRL_LTRIGGER   0x0100
#define SCE_CTRL_RTRIGGER   0x0200

#define SCE_CTRL_TRIANGLE   0x1000
#define SCE_CTRL_CIRCLE     0x2000
#define SCE_CTRL_CROSS      0x4000
#define SCE_CTRL_SQUARE     0x8000

u16 __sceCtrlGetButtons()
{
    u32 hostBut = host_getBut();
    u16 but = 0;
    but |= ((hostBut >> CTRL_SELECT  ) & 1) ? SCE_CTRL_SELECT   : 0;
    but |= ((hostBut >> CTRL_START   ) & 1) ? SCE_CTRL_START    : 0;
    but |= ((hostBut >> CTRL_UP      ) & 1) ? SCE_CTRL_UP       : 0;
    but |= ((hostBut >> CTRL_RIGHT   ) & 1) ? SCE_CTRL_RIGHT    : 0;
    but |= ((hostBut >> CTRL_DOWN    ) & 1) ? SCE_CTRL_DOWN     : 0;
    but |= ((hostBut >> CTRL_LEFT    ) & 1) ? SCE_CTRL_LEFT     : 0;
    but |= ((hostBut >> CTRL_LTRIGGER) & 1) ? SCE_CTRL_LTRIGGER : 0;
    but |= ((hostBut >> CTRL_RTRIGGER) & 1) ? SCE_CTRL_RTRIGGER : 0;
    but |= ((hostBut >> CTRL_TRIANGLE) & 1) ? SCE_CTRL_TRIANGLE : 0;
    but |= ((hostBut >> CTRL_CIRCLE  ) & 1) ? SCE_CTRL_CIRCLE   : 0;
    but |= ((hostBut >> CTRL_CROSS   ) & 1) ? SCE_CTRL_CROSS    : 0;
    but |= ((hostBut >> CTRL_SQUARE  ) & 1) ? SCE_CTRL_SQUARE   : 0;
    return but;
}

